home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_08 / 1108083a < prev    next >
Text File  |  1993-06-06  |  5KB  |  163 lines

  1.      /*******************************************
  2.      *
  3.      *   interior_outline(...
  4.      *
  5.      *   This function produces the outline of
  6.      *   any "holes" inside an object.  The
  7.      *   method is:
  8.      *      output = erosion of input
  9.      *      final output = input - output
  10.      *
  11.      *******************************************/
  12.  
  13. interior_outline(in_name, out_name, the_image,
  14.                  out_image, il, ie, ll, le, value,
  15.                  mask_type)
  16.    char   in_name[], out_name[];
  17.    int    il, ie, ll, le;
  18.    short  the_image[ROWS][COLS],
  19.           out_image[ROWS][COLS],
  20.           mask_type, value;
  21. {
  22.    int    a, b, count, i, j, k;
  23.    short  mask[3][3], max;
  24.    int    length, width;
  25.    struct tiff_header_struct image_header;
  26.  
  27.       /**************************************
  28.       *
  29.       *   Copy the 3x3 erosion-dilation mask
  30.       *   specified by the mask_type.
  31.       *
  32.       ***************************************/
  33.  
  34.    switch(mask_type){
  35.       case 1:
  36.          copy_3_x_3(mask, edmask1);
  37.          break;
  38.       case 2:
  39.          copy_3_x_3(mask, edmask2);
  40.          break;
  41.       case 3:
  42.          copy_3_x_3(mask, edmask3);
  43.          break;
  44.       case 4:
  45.          copy_3_x_3(mask, edmask4);
  46.          break;
  47.       default:
  48.          printf("\nInvalid mask type, using mask 4");
  49.          copy_3_x_3(mask, edmask4);
  50.          break;
  51.    }
  52.  
  53.    if(does_not_exist(out_name)){
  54.       printf("\n\n output file does not exist %s", out_name);
  55.       read_tiff_header(in_name, &image_header);
  56.       round_off_image_size(&image_header,
  57.                            &length, &width);
  58.       image_header.image_length = length*ROWS;
  59.       image_header.image_width  = width*COLS;
  60.       create_allocate_tiff_file(out_name, &image_header,
  61.                                 out_image);
  62.    }  /* ends if does_not_exist */
  63.  
  64.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  65.  
  66.    mask_erosion(in_name, out_name, the_image,
  67.                 out_image, il, ie, ll, le,
  68.                 value, mask_type);
  69.  
  70.    for(i=0; i<ROWS; i++)
  71.       for(j=0; j<COLS; j++)
  72.          the_image[i][j] =
  73.             the_image[i][j] - out_image[i][j];
  74.  
  75.    write_array_into_tiff_image(out_name, the_image,
  76.                                il, ie, ll, le);
  77.  
  78. }  /* ends interior_outline */
  79.  
  80.  
  81.  
  82.  
  83.  
  84.      /*******************************************
  85.      *
  86.      *   exterior_outline(...
  87.      *
  88.      *   This function produces the outline of
  89.      *   exterior of an object.  The
  90.      *   method is:
  91.      *      output = dilation of input
  92.      *      final output = output - input
  93.      *
  94.      *******************************************/
  95.  
  96. exterior_outline(in_name, out_name, the_image, out_image,
  97.           il, ie, ll, le, value, mask_type)
  98.    char   in_name[], out_name[];
  99.    int    il, ie, ll, le;
  100.    short  the_image[ROWS][COLS],
  101.           out_image[ROWS][COLS],
  102.           mask_type, value;
  103. {
  104.    int    a, b, count, i, j, k;
  105.    short  mask[3][3], max;
  106.    int    length, width;
  107.    struct tiff_header_struct image_header;
  108.  
  109.       /**************************************
  110.       *
  111.       *   Copy the 3x3 erosion-dilation mask
  112.       *   specified by the mask_type.
  113.       *
  114.       ***************************************/
  115.  
  116.    switch(mask_type){
  117.       case 1:
  118.          copy_3_x_3(mask, edmask1);
  119.          break;
  120.       case 2:
  121.          copy_3_x_3(mask, edmask2);
  122.          break;
  123.       case 3:
  124.          copy_3_x_3(mask, edmask3);
  125.          break;
  126.       case 4:
  127.          copy_3_x_3(mask, edmask4);
  128.          break;
  129.       default:
  130.          printf("\nInvalid mask type, using mask 4");
  131.          copy_3_x_3(mask, edmask4);
  132.          break;
  133.    }
  134.  
  135.    if(does_not_exist(out_name)){
  136.       printf("\n\n output file does not exist %s", out_name);
  137.       read_tiff_header(in_name, &image_header);
  138.       round_off_image_size(&image_header,
  139.                            &length, &width);
  140.       image_header.image_length = length*ROWS;
  141.       image_header.image_width  = width*COLS;
  142.       create_allocate_tiff_file(out_name, &image_header,
  143.                                 out_image);
  144.    }  /* ends if does_not_exist */
  145.  
  146.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  147.  
  148.    mask_dilation(in_name, out_name, the_image,
  149.                  out_image, il, ie, ll, le,
  150.                  value, mask_type);
  151.  
  152.    for(i=0; i<ROWS; i++)
  153.       for(j=0; j<COLS; j++)
  154.          the_image[i][j] =
  155.             out_image[i][j] - the_image[i][j];
  156.  
  157.    write_array_into_tiff_image(out_name, the_image,
  158.                                il, ie, ll, le);
  159.  
  160. }  /* ends exterior_outline */
  161.  
  162.  
  163.